﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WodLib
{
    /// <summary>
    /// Represents basic WoD attribute
    /// </summary>
    [Serializable()]
    [System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class Attribute : ICloneable
    {
        public event EventHandler HasChanged;

        private int dots = 0;

        /// <summary>
        /// Base, long term value of attribute.
        /// </summary>
        public int Dots
        {
            get
            {
                return dots;
            }
            set
            {
                dots = value;
                this.HasChanged(this, new EventArgs());
            }
        }

        /// <summary>
        /// List of attribute modifier affecting current value.
        /// </summary>
        public List<AttributeModifier> ModifiersList
        {
            get;
            set;
        }

        /// <summary>
        /// Sum of all modifiers. Is added to base value, to get current value.
        /// </summary>
        public int Modifier
        {
            get
            {
                int mod = 0;
                foreach (var item in ModifiersList)
                {
                    mod += item.Value;
                }
                return mod;
            }
        }

        /// <summary>
        /// Description of attribute.
        /// </summary>
        public string Description
        {
            get;
            set;
        }

        /// <summary>
        /// Repsents current value of attribute.
        /// </summary>
        public int CurrentValue
        {
            get
            {
                return Dots + Modifier;
            }
        }

        [System.ComponentModel.Browsable(false)]
        public AttributeCathegory Cathegory
        {
            get;
            set;
        }

        [System.ComponentModel.Browsable(false)]
        public TraitType TypeOfTrait
        {
            get;
            set;
        }

        public Attribute()
        {
            ModifiersList = new List<AttributeModifier>();
        }

        public Attribute(TraitType typeOfTrait, AttributeCathegory cathegory) : this()
        {
            TypeOfTrait = typeOfTrait;
            Cathegory = cathegory;
        }

        public override string ToString()
        {
            return CurrentValue.ToString();
        }

        #region ICloneable Members

        public object Clone()
        {
            Attribute tmp = (Attribute)this.MemberwiseClone();
            tmp.ModifiersList = new List<AttributeModifier>(this.ModifiersList.Capacity);
            foreach (var item in this.ModifiersList)
            {
                tmp.ModifiersList.Add(item);
            }
            return tmp;
        }

        #endregion
    }
}
